import {
  changeSheetName,
  createSheet,
  getConditions,
  getListConditions,
  getSheets,
  deleteSheet,
  backtest, saveBackTestReport, applyForShelf, getReportList, getAllStocks
} from '@/api/develop'

const sheet = {
  actions: {
    getSheets ({ commit }, userId) {
      return new Promise((resolve, reject) => {
        getSheets(userId).then(response => {
          commit('')
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    getListConditions ({ commit }) {
      return new Promise((resolve, reject) => {
        getListConditions().then(response => {
          commit('')
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    getConditions ({ commit }, conditionSheetId) {
      return new Promise((resolve, reject) => {
        getConditions(conditionSheetId).then(response => {
          commit('')
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    changeSheetName ({ commit }, sheet) {
      return new Promise((resolve, reject) => {
        changeSheetName(sheet.conditionSheetId, sheet.conditionSheetName).then(response => {
          commit('')
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    createSheet ({ commit }, data) {
      return new Promise((resolve, reject) => {
        createSheet(data.authorId, data.conditionSheetName, data.conditions).then(response => {
          commit('')
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    deleteSheet ({ commit }, conditionSheetId) {
      return new Promise((resolve, reject) => {
        deleteSheet(conditionSheetId).then(response => {
          commit('')
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    backtest ({ commit }, data) {
      return new Promise((resolve, reject) => {
        backtest(data.conditionSheetId, data.backTestStock, data.startTime, data.endTime).then(response => {
          commit('')
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    saveBackTestReport ({ commit }, data) {
      return new Promise((resolve, reject) => {
        saveBackTestReport(data.conditionSheetId, data.backTestStock, data.startTime, data.endTime, data.backTestYield).then(response => {
          commit('')
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    applyForShelf ({ commit }, data) {
      return new Promise((resolve, reject) => {
        applyForShelf(data.conditionSheetId, data.commodityName, data.commodityDescription, data.commodityPrice, data.authorId).then(response => {
          commit('')
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    getReportList ({ commit }, userId) {
      return new Promise((resolve, reject) => {
        getReportList(userId).then(response => {
          commit('')
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    getAllStocks ({ commit }, userId) {
      return new Promise((resolve, reject) => {
        getAllStocks().then(response => {
          commit('')
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    }
  }
}

export default sheet
